//
//  YQOrderRefundShowView.m
//  MuYing
//
//  Created by tbb on 2019/8/26.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "YQOrderRefundShowView.h"
#define kTABLEVIEW_H 177
@interface YQOrderRefundShowView ()
@property (nonatomic, copy) RefundShowViewResultBlack resultBlack;
@end

@implementation YQOrderRefundShowView
+ (void)refundShowViewViewResultBlack:(RefundShowViewResultBlack)resultBlack {
    YQOrderRefundShowView *screenView = [[YQOrderRefundShowView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    screenView.backgroundColor = HexColorA(0x000000, 0.2);//HexColor(0xF3F5F9);
    if (resultBlack) {
        screenView.resultBlack = resultBlack;
    }
    [screenView showSelctTableView];
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self.selectTableView registerNib:[UINib nibWithNibName:@"MYMySetTextCell" bundle:nil] forCellReuseIdentifier:@"MYMySetTextCell"];
        self.selectTableView.backgroundColor = UIColor.whiteColor;
        self.selectTableView.frame = CGRectMake(0, kYQPScreenHeight + kTABLEVIEW_H, kYQPScreenWidth, kTABLEVIEW_H);
        [self addSubview:self.selectTableView];
        [UIView roundedSetView:self.selectTableView cornerRadius:12 Type:(kRoundedSetViewTypeTRL)];
    }
    return self;
}

-(void)showSelctTableView {
    //1. 获取当前应用的主窗口
    
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    [keyWindow addSubview:self];
    // 浮现动画
    [UIView animateWithDuration:0.3 animations:^{
        self.selectTableView.top = kYQPScreenHeight - kTABLEVIEW_H-kHeight_Botton_SafeArea;
    }];
    
}

-(void)cancelSelctTableView {
    
    // 关闭动画
    [UIView animateWithDuration:0.5 animations:^{
        self.selectTableView.top = kYQPScreenHeight + kTABLEVIEW_H;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}


#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    MYMySetTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYMySetTextCell"];
    if (indexPath.row == 0) {
        cell.titleLb.text = kYQLS(@"仅退款");
    }else{
        cell.titleLb.text = kYQLS(@"退货退款");
    }
    cell.subLb.text = @"";
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 58;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.resultBlack(indexPath.row);
    [self cancelSelctTableView];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UILabel *lb = [[UILabel alloc] init];
    lb.textColor = kAPPMainTitleColor;
    lb.font = [UIFont systemFontOfSize:17 weight:(UIFontWeightMedium)];
    lb.textAlignment = NSTextAlignmentCenter;
    lb.text = kYQLS(@"申请售后");
    return lb;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 60;
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end

@end
